//引入一级路由组件
// import Home from '@/views/Home'
// import Search from '@/views/Search'
// import Register from '@/views/Register'
// import Login from '@/views/Login'
// import Detail from '@/views/Detail'
// import AddCartSuccess from '@/views/AddCartSuccess'
// import ShopCart from '@/views/ShopCart'
// import Trade from '@/views/Trade'
// import Pay from '@/views/Pay'
// import PaySuccess from '@/views/PaySuccess'
// import Center from '@/views/Center'
//引入二级路由组件
// import MyOrder from '@/views/Center/myOrder'
// import GroupOrder from '@/views/Center/groupOrder'

const foo = () =>{
    return import("@/views/Home")
}
/*当打包构建应用时，JavaScript 包会变得非常大，影响页面加载。如果我们能
把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就会更加高效 */
//路由配置信息
export default [
    {
        name: 'center',
        path: "/center",
        component: ()=>import('@/views/Center'),
        meta: { show: true },
        //子组件
        children: [
            {
                path: "myorder",
                component: ()=>import('@/views/Center/myOrder'),
            },
            {
                path: "grouporder",
                component: ()=>import('@/views/Center/groupOrder'),
            },
            {
                path: '/',
                redirect: "/center/myorder"
            }
        ]
    },
    {
        name: 'paysuccess',
        path: "/paysuccess",
        component: ()=>import('@/views/PaySuccess'),
        meta: { show: true },
        // beforeEnter: (to, from, next) => {
        //     if(from.path=="/pay"){
        //         next()
        //     }else{
        //         next(false)
        //     }
        // }
    },
    {
        name: 'pay',
        path: "/pay",
        component: ()=>import('@/views/Pay'),
        meta: { show: true },
        beforeEnter: (to, from, next) => {
            if(from.path=="/trade"){
                next()
            }else{
                next(false)
            }
        }
    },
    {
        name: 'trade',
        path: "/trade",
        component: ()=>import('@/views/Trade'),
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            //必须从购物车才能跳转
            if(from.path=="/shopcart"){
                next()
            }else{
                next(false)
            }
        }
    },
    {
        name: 'shopCart',
        path: "/shopCart",
        component: ()=>import('@/views/ShopCart'),
        meta: { show: true }
    },
    {
        name: 'addCartSuccess',
        path: "/addCartSuccess",
        component: ()=>import('@/views/AddCartSuccess'),
        meta: { show: true }
    },
    {
        name: 'home',
        path: "/home",
        component: foo,
        meta: { show: true }
    },
    {
        name: 'search',
        path: "/search/:keyword?",
        component: ()=>import('@/views/Search'),
        meta: { show: true }
    },
    {
        name: 'register',
        path: "/register",
        component: ()=>import('@/views/Register'),
        meta: { show: false }
    },
    {
        name: 'login',
        path: "/login",
        component: ()=>import('@/views/Login'),
        meta: { show: false }
    },
    {
        name: 'detail',
        path: "/detail/:skuid?",
        component: ()=>import('@/views/Detail'),
        meta: { show: true }
    },
    //重定向,项目运行时，访问/，立马定向到首页
    {
        path: '/',
        redirect: "/home"
    },
]